package com.yinhai.activity;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.yinhai.asynctask.AsyncTaskParam;
import com.yinhai.asynctask.NameValueParam;
import com.yinhai.asynctask.SubmitFeedbackTask;
import com.yinhai.cfg.AppConfig;
import com.yinhai.constant.UrlConstant;

/**
 * UpdateActivity （版本更新）
 * 
 * @author Juyon
 */
public class FeedbackActivity extends Activity {

	// 清除
	private TextView feedbackClear = null;

	// 确定
	private TextView feedbackSure = null;

	// 反馈内容
	private EditText feedbackContent = null;

	private static String msg = "软件建议提交成功...";;

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.app.Activity#onCreate(android.os.Bundle)
	 */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.more_feedback);

		feedbackSure = (TextView) findViewById(R.id.feedback_sure_tv);
		feedbackSure.setOnClickListener(onClickListener);

		feedbackClear = (TextView) findViewById(R.id.feedback_clear_tv);
		feedbackClear.setOnClickListener(onClickListener);

		feedbackContent = (EditText) findViewById(R.id.feedback_content_et);

	}

	public void doBack(View view) {
		onBackPressed();
	}

	private ProgressDialog progressDialog;

	private OnClickListener onClickListener = new OnClickListener() {

		@Override
		public void onClick(View v) {
			switch (v.getId()) {
			case R.id.feedback_sure_tv:
				if (feedbackContent.getText().toString().trim().length() > 0) {
					SubmitFeedbackTask loginTask = new SubmitFeedbackTask(
							FeedbackActivity.this, feedbackContent);
					AsyncTaskParam taskParam = new AsyncTaskParam(
							UrlConstant.LOCAL_URI + UrlConstant.FEEDBACK);
					SharedPreferences preferences = FeedbackActivity.this
							.getSharedPreferences(AppConfig.LOGIN_CONFIG,
									Context.MODE_PRIVATE);
					String user_code_str = preferences.getString("user_code",
							"");
					String user_phone_str = preferences.getString("name", "");
					List<NameValuePair> list = new ArrayList<NameValuePair>();
					NameValueParam nvp = new NameValueParam();
					nvp.setName("user_code");
					nvp.setValue(user_code_str);
					list.add(nvp);

					nvp = new NameValueParam();
					nvp.setName("user_phone");
					nvp.setValue(user_phone_str);
					list.add(nvp);

					nvp = new NameValueParam();
					nvp.setName("feedback");
					nvp.setValue(feedbackContent.getText().toString().trim());
					list.add(nvp);

					taskParam.setPostParam(list);
					loginTask.execute(taskParam);

					// new MyAsyncQueryHandler().execute(0);
					// 反馈内容提交到服务器
				} else {
					Toast.makeText(FeedbackActivity.this, "请输入软件建议。",
							Toast.LENGTH_SHORT).show();
				}

				break;

			case R.id.feedback_clear_tv:
				if (feedbackContent != null) {
					feedbackContent.setText("");
				}
				break;
			default:
				break;
			}
		}
	};

	/*
	 * private class MyAsyncQueryHandler extends AsyncTask<Integer, Integer,
	 * Integer> {
	 * 
	 * 
	 * (non-Javadoc)
	 * 
	 * @see android.os.AsyncTask#doInBackground(Params[])
	 * 
	 * @Override protected Integer doInBackground(Integer... params) { switch
	 * (params[0]) { case 0: try { Thread.sleep(2000); } catch
	 * (InterruptedException e) { e.printStackTrace(); } break;
	 * 
	 * default: break; } return 0; }
	 * 
	 * @Override protected void onPostExecute(Integer result) {
	 * super.onPostExecute(result); switch (result) { case 0:
	 * progressDialog.dismiss(); new AlertDialog.Builder(FeedbackActivity.this)
	 * .setTitle("提示") .setMessage(msg) .setPositiveButton("确定", new
	 * DialogInterface.OnClickListener() {
	 * 
	 * @Override public void onClick(DialogInterface dialog, int which) {
	 * dialog.dismiss(); } }).create().show(); if (feedbackContent != null) {
	 * feedbackContent.setText(""); } break;
	 * 
	 * default: break; } } }
	 */

}
